package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;



import vo.Customer;

public class CustomerDao {
	private Connection conn = null;
	public void initConnection() throws Exception {
		Class.forName("com.mysql.jdbc.Driver");
		conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/eams","root","root");
	}
	public void closeConnection() throws Exception{
		conn.close();
	}
	public Customer getCustomerByAccount(String account) throws Exception {
		String sql = "select account,password,cname"
				+ "from t_customer where account=?";
		this.initConnection();
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, account);
		ResultSet rs = ps.executeQuery();
		if(rs.next()) {
			Customer cus = new Customer();
			cus.setAccount(rs.getString("account"));
			cus.setPassword(rs.getString("password"));
			cus.setCname(rs.getString("cname"));
			return cus;
		}
		closeConnection();
		return null;
	}
}
